<html>
<head><meta charset="utf-8"><title>zero-sized dangling accesses/inbounds-offsets · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html">zero-sized dangling accesses/inbounds-offsets</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="159224404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159224404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159224404">(Feb 23 2019 at 10:47)</a>:</h4>
<p>Is the following code UB or not?</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Box</span>::<span class="n">new</span><span class="p">((((),),</span><span class="w"> </span><span class="mi">4</span><span class="p">));</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="p">((),)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">drop</span><span class="p">(</span><span class="n">b</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="c1">// getelementptr inbounds with offset 0 of a dangling pointer</span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">x_inner</span>: <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">x</span><span class="p">).</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="c1">// 0-sized access of a dangling pointer</span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p><a href="https://github.com/rust-rfcs/unsafe-code-guidelines/issues/93" target="_blank" title="https://github.com/rust-rfcs/unsafe-code-guidelines/issues/93">https://github.com/rust-rfcs/unsafe-code-guidelines/issues/93</a></p>



<a name="159224449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159224449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159224449">(Feb 23 2019 at 10:48)</a>:</h4>
<p>Notice that this better not be UB, we do this a lot in libstd:</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="p">((),)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="k">usize</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">_</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="c1">// getelementptr inbounds with offset 0 of a dangling pointer</span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">x_inner</span>: <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">x</span><span class="p">).</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="c1">// 0-sized access of a dangling pointer</span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="159627738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159627738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159627738">(Feb 28 2019 at 16:12)</a>:</h4>
<p>my sense is that a zero-sized load ought to be a "no-op" and hence never UB... is that too simplistic?</p>



<a name="159627891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159627891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159627891">(Feb 28 2019 at 16:15)</a>:</h4>
<p>that's kind of my understanding, except that maybe alignment should be checked</p>



<a name="159627962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159627962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159627962">(Feb 28 2019 at 16:16)</a>:</h4>
<p>(although now that I think about it... probably best to check it at reference creation?)</p>



<a name="159628397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159628397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159628397">(Feb 28 2019 at 16:21)</a>:</h4>
<p>Hmm, yes, maybe, although don't we create a "dummy pointer" like <code>0x1</code> or something for these?</p>



<a name="159628403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159628403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159628403">(Feb 28 2019 at 16:21)</a>:</h4>
<p>I forget</p>



<a name="159628419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159628419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159628419">(Feb 28 2019 at 16:21)</a>:</h4>
<p>I guess maybe we should just change the dummy pointer to <code>0x1000</code> :)</p>



<a name="159628460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159628460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159628460">(Feb 28 2019 at 16:22)</a>:</h4>
<p>or whatever the alignment is</p>



<a name="159629054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629054">(Feb 28 2019 at 16:28)</a>:</h4>
<p>I haven't heard anyone disagreeing that zero-sized accesses should be NOPs, the real tricky part are GEP-inbounds operations which can happen not only in the presence of ZSTs but also when you have e.g. an empty slice of non-ZST element type, so we can't simply side-step the LLVM questions surrounding those by not emitting LLVM IR for them</p>



<a name="159629228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629228">(Feb 28 2019 at 16:30)</a>:</h4>
<p>from my understanding, zero-sized accesses do have to be aligned and non-NULL. that's consistent with other 0-sized operations.</p>



<a name="159629252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629252">(Feb 28 2019 at 16:30)</a>:</h4>
<p>but yes, the real question here is GEPi</p>



<a name="159629289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629289">(Feb 28 2019 at 16:31)</a>:</h4>
<p>Yes, using "NOP" loosely here. The dangling-ness shouldn't be an issue is what I meant</p>



<a name="159629295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629295">(Feb 28 2019 at 16:31)</a>:</h4>
<p>but <span class="user-mention" data-user-id="124289">@rkruppe</span> I think an empty slice of non-ZST types is no problem, as you'll not GEPi into it</p>



<a name="159629324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629324">(Feb 28 2019 at 16:31)</a>:</h4>
<p>a non-empty slice of ZST types, however, is a problem</p>



<a name="159629433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629433">(Feb 28 2019 at 16:32)</a>:</h4>
<p>hm, you're right, i think i mixed something up<br>
but if ZSTs are involved, we know they're ZSTs and can modify our IR generation, can't we?</p>



<a name="159629487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629487">(Feb 28 2019 at 16:33)</a>:</h4>
<p>hm...</p>



<a name="159629563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629563">(Feb 28 2019 at 16:34)</a>:</h4>
<p>really I'd rather make LLVM change their GEPi semantics to delay the UB further -- OOB arithmetic doesnt go poison but "taints" the pointer such that using it for an actual access is UB</p>



<a name="159629572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629572">(Feb 28 2019 at 16:34)</a>:</h4>
<p>oh no I remember now, <em>slicing</em> an empty slice was the issue: <a href="https://github.com/rust-lang/rust/issues/54857" target="_blank" title="https://github.com/rust-lang/rust/issues/54857">https://github.com/rust-lang/rust/issues/54857</a></p>



<a name="159629587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629587">(Feb 28 2019 at 16:34)</a>:</h4>
<p>We already generate different code in rustc in presence of ZSTs IIRC</p>



<a name="159629589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629589">(Feb 28 2019 at 16:34)</a>:</h4>
<p>that'd solve all problems, and to my knowledge preserves everything the alias analysis needs</p>



<a name="159629590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629590">(Feb 28 2019 at 16:34)</a>:</h4>
<p>but well...</p>



<a name="159629613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629613">(Feb 28 2019 at 16:34)</a>:</h4>
<blockquote>
<p>oh no I remember now, <em>slicing</em> an empty slice was the issue: <a href="https://github.com/rust-lang/rust/issues/54857" target="_blank" title="https://github.com/rust-lang/rust/issues/54857">https://github.com/rust-lang/rust/issues/54857</a></p>
</blockquote>
<p>oh right we can always do that</p>



<a name="159629615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629615">(Feb 28 2019 at 16:34)</a>:</h4>
<p>not because we’re avoiding UB or anything of the sort, but rather simply to avoid unnecessary IR.</p>



<a name="159629647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629647">(Feb 28 2019 at 16:35)</a>:</h4>
<p>well really what I'd like to know is what the rules on the MIR side are. and then we can think about how to compile that to LLVM.</p>



<a name="159629678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159629678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159629678">(Feb 28 2019 at 16:35)</a>:</h4>
<p>and I see no good way to statically detect the MIR-level place projections that might be 0 and allow dangling pointers</p>



<a name="159630682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159630682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159630682">(Feb 28 2019 at 16:49)</a>:</h4>
<p>My unsubstantiated gut feeling is I don't feel we really need anything as tricky as GEPi for the optimizations that might reasonably happen at MIR level, it's more something we want to preserve for the later stages of codegen. However, for those later stages, it appears that it's not just AA that cares. Mostly it appears LLVM passes care about the "no wraparound" aspect.</p>



<a name="159633478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159633478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159633478">(Feb 28 2019 at 17:22)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> we use <code>heap::Empty&lt;T&gt;</code>, which is <code>align_of&lt;T&gt; as *mut T</code></p>



<a name="159633483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized%20dangling%20accesses/inbounds-offsets/near/159633483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/zero-sized.20dangling.20accesses.2Finbounds-offsets.html#159633483">(Feb 28 2019 at 17:22)</a>:</h4>
<p>aiui</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>